<?php
/* Web Statistics and Analytics Console (PHP)
 *  index.php
 *  Author: Trevor Bidyk
 *  Created: January 1, 2000
 *  Last modified: April 2, 2011
 *   (C) Us 2011
 *   Uses Simple PHP Framework, licensed under the FreeBSD license.
 *    View license in ./include/LICENSE.
 *   All rights reserved.
 */
require_once('./includes/master.inc.php');
require_once('./functions.statistics.php');
//$Auth->requireUser();
DisplayHeader('index');

$db = Database::getDatabase();

// Fetch new sessions for today.
$StartingDate = FormatDate(date('j'), date('n'), date('Y'));
$EndingDate = FormatDate((date('j') + 1), date('n'), date('Y'));

$Result = $db->query('SELECT Session.Session_Time, COUNT(Session.Session_Time) AS EventDate, Session.User_Agent FROM Event_Session AS Session WHERE Session.Session_Time BETWEEN \'' . $StartingDate . '\' AND \'' . $EndingDate . '\' ORDER BY Session.Session_Time DESC LIMIT 20');
$Rows = $db->getRows($Result);
$SessionBody = '';
foreach ($Rows As $Row) {
    $SessionBody .= '<tr><td>' . $Row['Session_Time'] . '</td><td>' . $Row['EventDate'] . '</td><td>' . $Row['User_Agent'] . '</td></tr>';
}

$Result = $db->query('SELECT Event.Payload, Event.Date_Event, Event.Reference FROM The_Event AS Event INNER JOIN Event_Type AS EventType ON EventType.Type_ID = Event.Type_ID WHERE Event.Date_Event BETWEEN \'' . $StartingDate . '\' AND \'' . $EndingDate . '\' ORDER BY Event.Date_Event DESC LIMIT 20');
$Rows = $db->getRows($Result);
$EventsBody = '';
foreach ($Rows As $Row) {
    $EventsBody .= '<tr><td>' . $Row['Date_Event'] . '</td><td>' . $Row['Payload'] . '</td><td>' . $Row['Reference'] . '</td></tr>';
}
?>
<div id="aac-subnavigation">&nbsp;</div>
<h2>Recently created sessions: </h2>
<span>These are sessions that have been created today.</span><br />
<br />
<table class="resulttable">
    <?php
    echo $SessionBody;
    ?>
</table>

<h2>Recently created events: </h2>
<span>These are events that have been created in sessions that have also been created today.</span><br />
<br />
<table class="resulttable">
    <?php
    echo $EventsBody;
    ?>
</table><br />
<br />
<?php
    DisplayFooter();
?>


